<template>
	<view>
    <!-- 1. 搜索栏 -->
    <view class="my-search-box">
          <my-search  @click="gotoSearch"></my-search >
    </view>

    <!-- 1. 轮播图广告区 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular>
		  <swiper-item v-for="(item,index) in swiperList" :key="index" >
		    <navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id">
           <image :src="item.image_src"></image>
        </navigator>
		  </swiper-item>
		</swiper>
    
    <!-- 2. 分类导航区 -->
    <view class="nav-list">
      <view class="nav-item" v-for="(item,i) in navList" :key="i" @click="gotoCateList(item)">
        <image :src="item.image_src" ></image>
      </view>
    </view>
    
    <!-- 3. 楼层面板区 -->
    <view class="floor-list">
      <view class="floor-item" v-for="(item,i) in floorList" :key="i">
      <!-- 3.1 楼层标题 -->
      <image :src="item.floor_title.image_src" class="floor-title"></image>
      <!-- 3.2 楼层图片区域 -->
      <view class="floor-pict">
        <!-- 3.2.1 左边的大图片 -->
        <navigator class="floor-pict-left" :url="item.product_list[0].url">
          <image :src="item.product_list[0].image_src" :style=
          "{width:item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
        </navigator><strong></strong>
        <!-- 3.2.2 右侧的四个小图片-->
        <view class="floor-pict-right">
          <navigator class="right-img-item" v-for="(item2,i2) in item.product_list" v-if="i2 > 0" :url="item2.url">
            <image :src="item2.image_src" :style="{width:item2.image_width + 'rpx'}" mode="widthFix"></image>
          </navigator>
        </view>
      </view>
       </view>
    </view>
    
	</view>
</template>

<script>
  import mixInBadge from "@/mixins/tabbar-badge.js"
	export default {
    mixins:[mixInBadge],
		data() {
			return {
        // 轮播图列表数据:
				swiperList: [],
        // 分类导航区数据
        navList: [],
        // 楼层区区域
        floorList: [],
			};
		},
    onLoad() {
      // 1. 查询轮播图列表
      this.getSwiperList()
      // 2. 获取分类导航数据
      this.getNavList()
      // 3. 获取楼层区域列表
      this.getFloorList()
    },
    methods:{
      // 1. 获取轮播图列表
      async getSwiperList(){
       const {data:res} = await uni.$http.get("/api/public/v1/home/swiperdata")
       console.log(res)
       if (res.meta.status !== 200) return uni.$showMsg()
       this.swiperList = res.message
      },
      // 2.  获取分类导航区列表
      async getNavList(){
        const {data:res} = await uni.$http.get("/api/public/v1/home/catitems")
        console.log("catitems:",res)
        if (res.meta.status !== 200) return uni.$showMsg()
        this.navList = res.message
      },
      // 3. 获取楼层列表数据
      async getFloorList(){
        const {data:res} = await uni.$http.get("/api/public/v1/home/floordata")
        console.log("floorList:",res)
        if(res.meta.status !== 200) return uni.$showMsg()
        this.floorList = res.message
        // 为楼层图片添加一个url地址
        this.floorList.forEach(f => {
          f.product_list.forEach(floor => {
            floor.url = "/subpkg/goods_list/goods_list?" + floor.navigator_url.split("?")[1]
          })
        })
      },
      // 跳转到分类面板(tabbar)
      gotoCateList(item){
        if(item.name === '分类'){
          uni.switchTab({
            url:'/pages/cate/cate'
          })
        }
      
      },
      // 到搜索页面
      gotoSearch(){
        uni.navigateTo({
          url: '/subpkg/search/search'
        })
      },
    }
	}
</script>

<style lang="scss">
  swiper{
    height: 330rpx;
    .swiper-item,image{
      width: 100%;
      height: 100%;
    }
  }
 .nav-list{
   display: flex;
   justify-content: space-around;
   margin: 15px 0;
   .nav-item{
     
     image{
       width: 128rpx;
       height: 140rpx;
     }
   }
 }
 .floor-list{
   .floor-item{
     .floor-title{
       height: 60rpx;
       display: flex;
       margin-top: 10px;
     }
     .floor-pict{
       display: flex;
       .floor-pict-left{
         
       }
       .floor-pict-right{
          display: flex;
          flex-wrap: wrap;
          justify-content: space-around;
         .right-img-item{
           
         }
       }
     }
   }
 }
 .my-search-box{
   position: sticky;
   top: 0;
   z-index: 999;
 }
</style>
